/*
 * @lc app=leetcode.cn id=1790 lang=javascript
 *
 * [1790] 仅执行一次字符串交换能否使两个字符串相等
 */

// @lc code=start
/**
 * @param {string} s1
 * @param {string} s2
 * @return {boolean}
 */
var areAlmostEqual = function (s1, s2) {
  const len = s1.length, pos = [];
  for (let i = 0; i < len; i++) {
    if (s1[i] !== s2[i]) {
      pos.push(i);
      if (pos.length > 2) {
        return false;
      }
    }
  }
  if (pos.length === 0) {
    return true;
  }
  if (pos.length === 1) {
    return false;
  }
  if (pos.length === 2) {
    const [a, b] = pos;
    return s1[a] === s2[b] && s1[b] === s2[a];
  }
};
// @lc code=end

